<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>JS盒子模型属性</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    .box {
      box-sizing: border-box;
      /* position: absolute;
      left: 50%;
      top: 50%;
      transform: translate(-50%, -50%); */
      margin: 20px auto;
      width: 300px;
      height: 300px;
      border: 10px solid lightblue;
      background: lightcyan;
      font-size: 18px;
      line-height: 35px;
    }
  </style>
</head>
<body>
  <div id="box" class="box">
    夫君子之行, 静以修身, 俭以养德, 非淡泊无以致远夫君子之行, 静以修身, 俭以养德, 非淡泊无以致远夫君子之行, 静以修身, 俭以养德, 非淡泊无以致远夫君子之行, 静以修身, 俭以养德, 非淡泊无以致远夫君子之行, 静以修身, 俭以养德, 非淡泊无以致远
  </div>
  <script>
    let box = document.getElementById('box');
    // JS实现居中: (一屏幕的宽度 - 盒子的宽度) / 2
    let winW = document.documentElement.clientWidth;
    let winH = document.documentElement.clientHeight;
    box.style.position = 'absolute';
    box.style.left = (winW - 300) / 2 + 'px';
    box.style.top = (winH - 300) / 2 + 'px';
  </script>
</body>
</html>